<?php

namespace app\admin\controller;

use think\Controller;
use think\Request;
use think\Session;
use think\Db;

class Writer extends Controller
{
    public function writer_apply()
    {
        $data = Db::table('mh_writer_apply')->select();
        return view('writer/writer_apply',[
            'data'=>$data
        ]);
    }

    public function writer_user()
    {
        $data = Db::table('mh_writer_user')->select();
        return view('writer/writer_user',[
            'data'=>$data
        ]);
    }

    public function apply_tongyi($id)
    {
        $data = Db::table('mh_writer_apply')->where(['user_id'=>$id])->find();
        unset($data['id']);
        $res = Db::table('mh_writer_user')->insert($data);
        $ress = Db::table('mh_writer_apply')->where(['user_id'=>$id])->delete();
        if($ress){
            $this->success('同意成功', 'admin/writer/writer_apply');
        } else {
            $this->error('同意失败');
        }

    }

    public function apply_dahui($id)
    {
        $ress = Db::table('mh_writer_apply')->where(['user_id'=>$id])->delete();
        if($ress){
            $this->success('打回成功', 'admin/writer/writer_apply');
        } else {
            $this->error('打回失败');
        }
    }
    public function del_writer($id)
    {
        $ress = Db::table('mh_writer_user')->where(['user_id'=>$id])->delete();
        if($ress){
            $this->success('取消成功', 'admin/writer/writer_user');
        } else {
            $this->error('取消失败');
        }
    }
}
